package com.lovar.gaming.core.util;

import cn.hutool.extra.spring.SpringUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 * 消息工具类
 *
 * @author Champagne9
 * @date 2024/3/7
 * @template
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MessageUtils {

    private static final MessageSource MESSAGE_SOURCE = SpringUtil.getBean(MessageSource.class);

    public static String message(String code) {
        return MESSAGE_SOURCE.getMessage(code, null, LocaleContextHolder.getLocale());
    }

    public static String message(String code, Object[] args) {
        return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale());
    }

}
